﻿Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.Web.Security
Imports Entidades
Imports LogicDAO


Partial Class Logeo
    Inherits System.Web.UI.Page
    Dim clienteBE As New Entidades.Cliente
    Dim cliente As New LogicDAO.ClienteDAO
    Dim usuario As New LogicDAO.UsuarioDAO

    Protected Sub ButtonIngresar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonIngresar.Click
        Dim dtC As New DataTable

        dtC = cliente.getCliente(UsuarioTextBox.Text, ContrasenaTextBox.Text)

        Dim dtU As New DataTable
        dtU = usuario.getUsuario(UsuarioTextBox.Text, ContrasenaTextBox.Text)


        If UsuarioTextBox.Text.Equals("") Or ContrasenaTextBox.Text.Equals("") Then
            MsgBox("Escriba usuario o contraseña", MsgBoxStyle.Critical, "ERROR")
            UsuarioTextBox.Text = ""
            ContrasenaTextBox.Text = ""
            'ElseIf txtUsuario.Text <> clienteBE.Email Or txtClave.Text <> clienteBE.Password Then
            '    MsgBox("Usuario o contraseña incorrecta", MsgBoxStyle.Critical, "ERROR")
            '    txtUsuario.Text = ""
            '    txtClave.Text = ""
        ElseIf dtC.Rows.Count > 0 Then
            FormsAuthentication.RedirectFromLoginPage(Me.UsuarioTextBox.Text, False)
            Dim codigo As String = dtC.Rows.Item(0).Item(0).ToString
            Dim estado As String = dtC.Rows.Item(0).Item(6).ToString
            If estado = "ACTIVADO" Then

                Session("cliente") = codigo
                Response.Redirect("ManteniminetoCliente.aspx")
            Else
                MsgBox("UTDS HA SIDO DESACTIVADO", MsgBoxStyle.Exclamation, "MENSAJE")
                Response.Redirect("Logeo.aspx")
            End If
        ElseIf dtU.Rows.Count > 0 Then
            FormsAuthentication.RedirectFromLoginPage(Me.UsuarioTextBox.Text, False)
            Dim codigo As String = dtU.Rows.Item(0).Item(0).ToString
            Response.Redirect("AdministradorInicio.aspx?codigo=" + codigo)

        End If
    End Sub
End Class
